package com.fang.algorithm.zuo.tree;

import com.fang.algorithm.zuo.linked.Test01_ReverseLinkedList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author lingxiao.fang
 * @Desc todo
 * @createTime 2025/3/4 13:46
 */
public class Test03_GenTrees {

    private static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public static void main(String[] args) {
        List<TreeNode> genTrees = genTrees(3);
        printNode(genTrees.get(0));
    }

    public static List<TreeNode> genTrees(int n) {
        if (n == 0) {
            return new ArrayList<>();
        }
        TreeNode head = new TreeNode();
        process(1, n, n, head);
        List<TreeNode> list = new ArrayList<>();
        list.add(head);
        return list;
    }

    private static void process(int curr, int high, int val, TreeNode head) {
        if (curr > high && val > 0) {
            return;
        }
        head.val = val;
        head.left = new TreeNode();
        head.right = new TreeNode();
        curr++;
        process(curr, high, val - 1, head.left);
//        process(curr, high, val - 1, head.right);
    }

    private static void printNode(TreeNode node) {
        List<Integer> arr = new ArrayList<>();
        prePrint(node, arr);
        arr.forEach(System.out::print);
    }

    private static void prePrint(TreeNode node, List<Integer> arr) {
        if (node == null) {
            return;
        }
        arr.add(node.val);
        prePrint(node.left, arr);
        prePrint(node.right, arr);
    }
}
